<extend name="Public/base" />
<block name="content">
    <center>
        <div class="row" style="margin-top: 5%">
            <div class="medium-4 columns">
                <input type="text" id="name" placeholder="请输入教师姓名" style="height:33px;border-radius: 5px">
            </div>
            <div class="medium-4 columns">
                <input type="text" id="class" placeholder="请输入班级" style="height:33px;border-radius: 5px">
            </div>
            <div class="medium-4 columns" >
                <buttom class="button tiny  radius " onclick="sear()">查找</buttom>
            </div>
        </div>
        <table style="margin-top: 5%">
            <theat>
                <th>教师姓名</th>
                <th style="text-align: center">所教班级</th>
                <th style="text-align: center">任命</th>
        </theat>
        <tbody id="tb">
            <volist name="tc" id="tc">
                <tr id="row_<{$tc.teacher_id}>">
                    <td><{$tc.tname}></td>
                    <td>
                        <input type="text" class="cs" disabled value="<{$tc['tclass']?$tc['tclass']:'空闲'}>" style="height:25px;border-radius: 5px">
                        <input type="hidden" class="ts" value="<{$tc.teacher_id}>">
                    </td>
                    <td>
                        <buttom class="button tiny  radius xg" onclick="xg(<{$tc.teacher_id}>)">编辑</buttom>
                        <buttom class="button tiny  radius bc" style="display:none" onclick="bc(<{$tc.teacher_id}>)">保存</buttom>
                    </td>
                </tr>
            </volist>
        </tbody>
    </table>
    </center>
    <script>
        function xg(a) {
            $('#row_'+a+' .xg').hide();
            $('#row_'+a+' .bc').show();
            $('#row_'+a+' .cs').prop('disabled',false);
        }
        function bc(a) {
                $('#row_'+a+' .bc').hide();
                $('#row_'+a+' .xg').show();
                $('#row_'+a+' .cs').prop('disabled', true);
                var cla = $('#row_'+a+' .cs').val();
                var tid = $('#row_'+a+' .ts').val();
                var data={
                    teacher_id:tid,
                    tclass:cla,
                };
                $.post("<{:U('ClassTeach/edit')}>",data,function (data) {
                    alert(data);
                })
        }
        function sear(){
            var data={
                tname:$('#name').val(),
                class:$('#class').val(),
            };
            if(!data.tname && !data.class){
                alert('请输入一项');
            }
            $.post("<{:U('ClassTeach/getTeacher')}>",data,function (data) {
                var html='';
                for(i in data){
                    var kx=data[i]['tclass']?data[i]['tclass']:'空闲'
                    html+='<tr id="row_'+data[i].teacher_id+'">'
                            +'<td>'+data[i].tname+'</td>'
                            +'<td>'
                            +'<input type="text" class="cs" disabled value="'+kx+'" style="height:25px;border-radius: 5px">'
                            +'<input type="hidden" class="ts" value="'+data[i].teacher_id+'">'
                            +'</td>'
                            +'<td>'
                            +'<buttom class="button tiny  radius xg" onclick="xg('+data[i].teacher_id+')">编辑</buttom>'
                            +'<buttom class="button tiny  radius bc" style="display:none" onclick="bc('+data[i].teacher_id+')">保存</buttom>'
                            +'</td>'
                            +'</tr>'
                }
                $('#tb').html(html);
            })
        }
    </script>
</block>